import { reactive, ref } from 'vue'
import AppList from '@/entry_mobile/views/AppList/index.vue'
import AppSearch from '@/entry_mobile/views/AppSearch/index.vue'
import { apiInit } from '@/services'
import { isMoreTabs } from '@/utils/common'
export default function useAppCenter() {
	const api = apiInit()
	const component: any = ref(AppList)
	const SearchList: any = ref()
	const searchKeyWord = ref('')
	const searching = ref(false)
	const changeComponent = (componentName: string) => {
		component.value = componentName === 'AppSearch' ? AppSearch : AppList
	}
	const search = async (keyword: string) => {
		searching.value = true
		searchKeyWord.value = keyword
		const { code, data } = await api.default.GroupListAppPrivateV2POST({
			payload: {
				keyword: keyword,
				enable_multiple_tab: isMoreTabs(),
			},
		})
		if (code === '000000') {
			SearchList.value = data
		} else {
		}
		searching.value = false
	}
	return {
		component,
		SearchList,
		changeComponent,
		search,
		searching,
		searchKeyWord,
	}
}
